#ifndef __MP_MQTT_CLIENT_PUBLISH_H__
#define __MP_MQTT_CLIENT_PUBLISH_H__

#include <string>
#include <vector>
#include <map>

#include "mqtt_client_context.h"

#include "logger.h"
#include "eventloop.h"
#include "mqtt_packet.h"

namespace Gazella {

struct MqttClientPublishInfo {
    uint8_t qos;
    MqttPublishQosStep qos_step = MQTT_PUBLISH_QOS_STEP_NONE;

    bool pub_ok = false;
    uint32_t timeout = 0;

    MqttPacketPublish publish_packet;
};

class MqttClientPublish {
public:
    MqttClientPublish();
    ~MqttClientPublish();

    void add_publish(const MqttClientPublishInfo& publish);
    void set_publish(uint16_t packet_id, MqttPublishQosStep step);

    void set_net_context(std::shared_ptr<MqttClientContext>& context);

private:
    void __check_publish_qos_timer_cb(ev::timer &w, int revents);

private:
    ev::timer m_check_publish_qos_timer;

    std::vector<MqttClientPublishInfo> m_publish_list;

    Logger *m_logger;

    std::shared_ptr<MqttClientContext> m_context = nullptr;
};
}

#endif
